package com.kvsl.wechatmonitor.controller;

import com.kvsl.wechatmonitor.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {

    private MessageService messageService;

    @Autowired
    public MessageController(MessageService messageService) {
        this.messageService = messageService;
    }

    /**
     * 查询某人发送过的消息
     * @param sender 消息发送人
     * @return sender发送的消息列表
     */
    @GetMapping("/sender/{sender}")
    public Object showMessage(@PathVariable("sender") String sender) {
        return messageService.searchMessage(sender);
    }

    /**
     * 返回一天内的消息
     * @return 一天内的消息列表
     */
    @GetMapping("/message/latest")
    public Object showLastMessage() {
        return messageService.searchRecentMessage();
    }
}
